<?php

namespace app\common\model;

use think\Request;
use think\Model;

class UserDetail extends Model
{

    // 开启自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';
    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    // 定义字段类型
    protected $type = [
    ];

    /**
     * 获取列表
     */
    public function getList($user_id=0)
    {
        // 筛选条件
        $filter = [];
        $user_id > 0 && $filter['user_id'] = $user_id;

        // 执行查询
        $list = $this->where($filter)
            ->order('id','desc')
            ->paginate(15, false, [
                'query' => Request::instance()->request()
            ]);
        return $list;
    }

    /**
     * 获取详情
     */
    public static function getDetail($where)
    {
        return self::where($where)->find();
    }

    /**
     * 获取详情
     */
    public static function getUserDetail($user_id)
    {
        return self::where(['user_id'=>$user_id])->find();
    }
}
